package com.megalith.controller;

import com.megalith.dto.ActivityRebackDTO;
import com.megalith.dto.ManagerVerifyDTO;
import com.megalith.dto.StaffApplyDTO;
import com.megalith.dto.StaffLeaveTicketDTO;
import com.megalith.service.HolidayService;
import com.megalith.utils.RequestResponseUtil;
import com.megalith.vo.HistoricActivityInstanceEntityVO;
import com.megalith.vo.HistoricTaskInstanceVO;
import com.megalith.vo.Result;
import com.megalith.vo.TaskEntityVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description holiday请假流程接口管理
 * @Author lfp
 * @Date 2022/7/15
 * @Version 1.0
 */
@RestController
@Api(tags = "holiday请假流程接口管理")
@RequestMapping("holiday")
public class HolidayController {
    @Autowired
    private HolidayService holidayService;

    /**
    *@Description 查询请假流程所有现有流程节点
    *@Author lfp
    *@Date 2022/7/15
    *@param 
    *@Return 
    */
    @ApiOperation(value = "查询请假流程所有现有流程task集合信息")
    @GetMapping("active/task/list")
    public Result<List<TaskEntityVO>> queryActiveHolidayProcessTaskList(){
        return Result.ok(holidayService.queryActiveHolidayProcessTaskList());
    }

    /**
    *@Description 根据员工标识，发起请假流程
    *@Author lfp
    *@Date 2022/7/15
    *@param applyDTO
    *@param result
    *@Return
    */
    @ApiOperation(value = "发起请假流程")
    @PostMapping("process/start")
    public Result startHolidayProcess(@Validated @RequestBody StaffApplyDTO applyDTO, BindingResult result){
        if (result.hasErrors()) {
            return RequestResponseUtil.doBindingResultHandel(result);
        }else {
            return Result.ok(holidayService.startHolidayProcess(applyDTO));
        }
    }

    /**
    *@Description 填写请假申请单
    *@Author lfp
    *@Date 2022/7/15
    *@param leaveTicketDTO
    *@param result
    *@Return
    */
    @ApiOperation(value = "填写请假申请单")
    @PostMapping("ticket/fill")
    public Result fillHolidayTicket(@Validated @RequestBody StaffLeaveTicketDTO leaveTicketDTO, BindingResult result){
        if (result.hasErrors()) {
            return RequestResponseUtil.doBindingResultHandel(result);
        }else {
            return holidayService.fillHolidayTicket(leaveTicketDTO);
        }
    }

    /**
    *@Description 部门经理/总经理审批
    *@Author lfp
    *@Date 2022/7/15
    *@param managerVerifyDTO
    *@param result
    *@Return
    */
    @ApiOperation(value = "部门经理/总经理审批/人力资源")
    @PostMapping("manager/verify")
    public Result managerVerifyHolidayTask(@Validated @RequestBody ManagerVerifyDTO managerVerifyDTO, BindingResult result){
        if (result.hasErrors()) {
            return RequestResponseUtil.doBindingResultHandel(result);
        }else {
            return holidayService.managerVerifyHolidayTask(managerVerifyDTO);
        }
    }


    /**
    *@Description 流程回退
    *@Author lfp
    *@Date 2022/7/15
    *@param rebackDTO
    *@param result
    *@Return
    */
    @ApiOperation(value = "流程回退")
    @PostMapping("actibity/reback")
    public Result processActivityReback(@Validated @RequestBody ActivityRebackDTO rebackDTO, BindingResult result){
        if (result.hasErrors()) {
            return RequestResponseUtil.doBindingResultHandel(result);
        }else {
            holidayService.processActivityReback(rebackDTO);
            return Result.ok();
        }
    }


    /**
    *@Description 根据流程实例编号，查询历史任务信息
    *@Author lfp
    *@Date 2022/7/15
    *@param processInstanceId
    *@Return 
    */
    @ApiOperation("根据流程实例编号，查询历史任务信息")
    @GetMapping("task/history/list/{processInstanceId}")
    public Result<List<HistoricTaskInstanceVO>> queryHistoricTaskInfoList(@PathVariable String processInstanceId){
        return Result.ok(holidayService.queryHistoricTaskInfoList(processInstanceId));
    }

    /**
    *@Description 根据流程实例编号，查询历史活动信息
    *@Author lfp
    *@Date 2022/7/15
    *@param processInstanceId
    *@Return
    */
    @ApiOperation("根据流程实例编号，查询历史活动信息")
    @GetMapping("activity/history/list/{processInstanceId}")
    public Result<List<HistoricActivityInstanceEntityVO>> queryHistoricActivityInfoList(@PathVariable String processInstanceId){
        return Result.ok(holidayService.queryHistoricActivityInfoList(processInstanceId));
    }
}
